<template>
    <popup
        ref="popupRef"
        width="30%"
        title='签收面板'
        class="bg-page"
        :async="true"
        confirmButtonText="确认签收"
        cancelButtonText="异常签收"
        @confirm="handleConfirm"
        @close="handleClose"
    >
        
        <el-form class="mb-10  mt-5  " :model="formData" label-width="150px">
            
            <el-form-item label="寄送物流公司" prop="logisticCompany">
                <el-input
                    v-model="formData.logisticCompany"
                    class="w-10/12"
                    disabled>
                </el-input>
            </el-form-item>
            
            
            <el-form-item label="寄送物流单号" prop="logisticNumber">
                <el-input
                    v-model="formData.logisticNumber"
                    class="w-10/12"
                    disabled>
                </el-input>
            </el-form-item>
            
            
            <el-form-item label="寄件人名称" prop="userPhone">
                <el-input
                    v-model="formData.userName"
                    class="w-10/12"
                    disabled>
                </el-input>
            </el-form-item>
            
            <el-form-item label="寄件人电话" prop="logisticNumber">
                <el-input
                    v-model="formData.userPhone"
                    class="w-10/12"
                    disabled>
                </el-input>
            </el-form-item>
        
        </el-form>
    
    
    </popup>

</template>

<script lang='ts' setup>

import {FormInstance} from "element-plus";
import Popup from "@/components/popup/index.vue";
import {UnwrapNestedRefs} from "@vue/reactivity";

import AfterSaleOrderDetailDTO from "@/api/afterSale/order/dto/AfterSaleOrderDetailDTO";
import {Ref} from "vue";

import {handleSignerSaleOrder} from "@/api/afterSale/order/AfterSaleOrderController";
import feedback from "@/utils/feedback";
import IdRequest from "@/api/baisc/IdRequest";

const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>()
const loading: Ref<boolean> = ref(false)


/**
 * 定义提交数据
 */
let formData: UnwrapNestedRefs<AfterSaleOrderDetailDTO> = reactive(new AfterSaleOrderDetailDTO())



/**
 *  确认提交
 *
 * @author 徐寿春
 * 2023/4/8 u
 */
function handleConfirm() {
    let idRequest = new IdRequest();
    idRequest.id = formData.afterSaleOrderId
    handleSignerSaleOrder(idRequest).then(() => {
            feedback.msgSuccess('签收成功')
            popupRef.value?.close()
            emit('confirm')
        }
    )
    
    
}


/**
 * 弹窗打开
 *
 * @author 徐寿春
 * 2023/5/6 14:40
 */
function open(row: any) {
    for (let formDataKey in formData) {
        //@ts-ignore
        formData[formDataKey] = row[formDataKey]
    }
    popupRef.value?.open()
}

/**
 *  异常签收
 *
 * @author 徐寿春
 * 2023/4/8 13:28
 */
function handleClose() {
    emit('close')
}

const emit = defineEmits(['confirm', 'close'])
defineExpose({
    open
})


</script>

